package cn.ac.cintcm.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import cn.ac.cintcm.util.DateUtil;

@Entity
@Table(name="HC_FB")
public class FeedBack extends BaseObject {
	
	@Id@GeneratedValue(strategy=GenerationType.AUTO)
	private Long id;
	@Column(name="good")
	private boolean isGood = true;
	@Column(name="checked")
	private boolean checked = false;
	
	@Column(length=1000)
	private String content; //反馈内容
	
	@ManyToOne(optional=false, fetch = FetchType.EAGER)
	@JoinColumn(name="therapy", nullable=false)
	private Therapy therapy = new Therapy(); //反馈所对应的诊疗
	
	@ManyToOne(optional=false, fetch = FetchType.EAGER)
	@JoinColumn(name="patient", nullable=false)
	private User patient = new User();
	
	@ManyToOne(optional=false, fetch = FetchType.EAGER)
	@JoinColumn(name="doctor", nullable=false)
	private User doctor = new User();
	
	private boolean author = false; //反馈者 doctor true, patient false
	
	@Column
	private Date fdate; //反馈时间
	@Transient
	private String dateStr;
	@Transient
	private String contentStr;
	/**
	 * 
	 */
	private static final long serialVersionUID = 2607658606332529202L;


	@Override
	public int hashCode() {
		final int PRIME = 31;
		int result = 1;
		result = PRIME * result + (int) (id ^ (id >>> 32));
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		final FeedBack other = (FeedBack) obj;
		if (id != other.id)
			return false;
		return true;
	}

	@Override
	public String toString() {
		return null;
	}

	public String getContent() {
		return content;
	}
	
	public String getContentStr() {
		contentStr = content;
		if (contentStr != null) {
			contentStr = contentStr.replaceAll("\r\n|\r|\n", "<br>");
		}
		return contentStr;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public Date getFdate() {
		return fdate;
	}
	
	public String getDateStr() {
		dateStr = DateUtil.convertDateToString(fdate);
		return dateStr;
	}

	public void setFdate(Date fdate) {
		this.fdate = fdate;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Therapy getTherapy() {
		return therapy;
	}

	public void setTherapy(Therapy therapy) {
		this.therapy = therapy;
	}

	public boolean getIsGood() {
		return isGood;
	}

	public void setIsGood(boolean isGood) {
		this.isGood = isGood;
	}

	public User getDoctor() {
		return doctor;
	}

	public void setDoctor(User doctor) {
		this.doctor = doctor;
	}

	public User getPatient() {
		return patient;
	}

	public void setPatient(User patient) {
		this.patient = patient;
	}

	public boolean getChecked() {
		return checked;
	}

	public void setChecked(boolean checked) {
		this.checked = checked;
	}

	public boolean getAuthor() {
		return author;
	}

	public void setAuthor(boolean author) {
		this.author = author;
	}

}
